package com.learn.xueer.ui.adapter

import android.widget.ImageView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import com.learn.xueer.R
import com.learn.xueer.data.model.bean.BookInfo
import com.learn.xueer.data.model.bean.BookSectionResponse
import com.learn.xueer.data.model.bean.HearSayResponse
import com.learn.xueer.data.model.bean.VipList
import com.learn.xueer.data.model.bean.VipResponse

class BookAdapter(data: MutableList<HearSayResponse>) :
    BaseQuickAdapter<HearSayResponse, BaseViewHolder>(
        R.layout.item_vip, data
    ) {
    override fun convert(holder: BaseViewHolder, item: HearSayResponse) {
        holder.setText(R.id.tv_name, item.productName)
        holder.setGone(R.id.iv_row,false)
        val bookInfos = Gson().fromJson<MutableList<BookInfo>>(
            item.packageinfo,
            object : TypeToken<MutableList<BookInfo>>() {}.type
        )
        var countStr = ""
        bookInfos.forEach {
            countStr = countStr + it.title + it.content + "\r\n"
        }
        countStr.removeRange(countStr.length - 1, countStr.length)
        holder.setText(R.id.tv_grade, countStr)
        if (!item.cover_full.isNullOrEmpty()){
            var view = holder.getView<ImageView>(R.id.iv_logo)
            Glide.with(this.context)
                .load(item.cover_full)
                .transition(DrawableTransitionOptions.withCrossFade(500))
                .placeholder(R.mipmap.default_book)
                .error(R.mipmap.default_book)
                .into(view)
        }


    }
}